﻿<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/sys_include.jsp"%>

<div style="padding: 4px;"><table id="qfd_list_grid" width="100%"></table></div>
<div id="qfd_list_grid_page" style="padding: 4px;"></div>

<div id="qfd_list_window" class="easyui-dialog" title="祈福灯制作">
   <form id="qfd_list_form" name="qfd_list_form" method="POST" enctype="multipart/form-data" 
         action="qfd/Qfd/saveData.do" target="qfd_list_upload_iframe">
      <input type="hidden" id="qfd_list_req_param" name="qfd_list_req_param"/>
      
      <div id="qfd_list_errmsg"></div>
      <table width="100%" align="center">
      
         <tr>
            <td align="right">名称</td>
            <td align="left"><input id="qfd_list_qfdName" name="qfd_list_qfdName" value="" /></td>
         </tr>
         
         <tr>
            <td align="right">收费</td>
            <td align="left">
               <select id="qfd_list_chargeflag" name="qfd_list_chargeflag" class="easyui-combobox" style="width:64px;">
                   <option value="0">免费</option>
                   <option value="1">收费</option>
               </select>
            </td>
         </tr>
         
         <tr>
            <td align="right">价格(分)</td>
            <td align="left">
               <input id="qfd_list_qfdPrice" name="qfd_list_qfdPrice" value="" />
            </td>
         </tr>
         
         <tr>
            <td align="right">类别</td>
            <td align="left">
               <select id="qfd_list_qfdType" name="qfd_list_qfdType" class="easyui-combobox" style="width:128px;">
                   <option value="招财">招财</option>
                   <option value="事业">事业</option>
                   <option value="升学">升学</option>
                   <option value="爱情">爱情</option>
                   <option value="求子">求子</option>
                   <option value="四季平安">四季平安</option>
                   <option value="辟邪">辟邪</option>
                   <option value="安康">安康</option>
                   <option value="福禄">福禄</option>
                   <option value="长寿">长寿</option>
               </select>
            </td>
         </tr>

         <tr>
            <td align="right">上传图片</td>
            <td align="left">
               <input id='qfd_list_imgfile' name='qfd_list_imgfile' type='file' 
                      size="24" onChange="fun_qfd_list_preview(this)"/>
            </td>
         </tr>

         <tr style='display:none'>
            <td align="right">图片预览</td>
            <td align="left">
               <img id="qfd_list_img_preview" src="FILE:///G:/yzm.gif"/>
            </td>
         </tr>

         <tr>
            <td colspan="2" align="center">
               <input type="button" id="qfd_list_submit_btn" value="保　存"/>&nbsp;&nbsp; 
               <input type="button" id="qfd_list_close_btn" value="关　闭"/>
            </td>
         </tr>
      </table>
      
      <iframe name="qfd_list_upload_iframe" id="qfd_list_upload_iframe" style='display:none'></iframe>
   </form>
</div>



<script>
   closeUIDialog('qfd_list_window');
   
   jQuery("#qfd_list_grid").jqGrid(
   {
      caption : 
         '<a href="javascript:fun_qfd_list_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
         '<a href="javascript:fun_qfd_list_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
         '<a href="javascript:fun_qfd_list_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
      datatype: "json", //JSON格式数据
      hidegrid: false, //不显示收缩
      autowidth: true,
      url:'qfd/Qfd/list.do', //请求后台返回列表数据的URL
      height: '100%',
      forceFit: true,//调整宽度不改变表格宽度
      width: '100%',
      colNames:[ '编号', '图片', '名称', '收费', '价格', '销售', '人气', '类型', '创建时间', '更新时间'],
      //sortable:设置该字段是否进行排序,sorttype:排序的数据类型 
      colModel:[
      {name:'qfdId',index:'qfdId', width:1,sorttype:'int',sortable:false},
      {name:'imgUrl',index:'imgUrl',width:120,sortable:false, formatter:fun_qfd_list_imgformat},
      {name:'qfdName',index:'qfdName',width:160,sortable:false},
      {name:'chargeFlag',index:'chargeFlag',width:80,sortable:false,
          formatter:'select',editoptions:{value:"0:免费;1:收费;"}},
      {name:'qfdPrice',index:'qfdPrice',width:80,sortable:false},
      {name:'saleCount',index:'saleCount',width:80,sortable:false},
      {name:'popularCount',index:'popularCount',width:80,sortable:false},
      {name:'qfdType',index:'qfdType',width:120,sortable:false},
      {name:'createDateString',index:'createDateString',width:1,sortable:false},
      {name:'updateDateString',index:'updateDateString',width:1,sortable:false},
      
      ],
      multiselect: true,
      toolbar:[false,'top'],
      rowNum: 15,
      rowList:[15, 50, 100],
      rownumbers : true,
      viewrecords: true,
      sortname:  "qfdId",
      sortorder: "desc",
      pager: '#qfd_list_grid_page',
      jsonReader: {     
         root: 'dataRows',   
         repeatitems : false     
      }
   });
   jQuery("#qfd_list_grid").jqGrid('hideCol', ['qfdId', 'createDateString', 'updateDateString']);

   function fun_qfd_list_imgformat(cellvalue, options, rowObject)
   {  
       return '<img width=80 height=80 src="' + cellvalue + '" />';  
   }
   
   $('#qfd_list_close_btn').unbind('click');
   $('#qfd_list_close_btn').click(function()
   {
      closeUIDialog('qfd_list_window');
   });

   $('#qfd_list_submit_btn').unbind('click');
   $('#qfd_list_submit_btn').click(function()
   {
      fun_qfd_list_submit();
   });
   
   var qfd_list_saveflag=true;
   
   function fun_qfd_list_add()
   {
      $("#qfd_list_form")[0].reset(); 
      qfd_list_saveflag = true; 
      
      openUIDialog('qfd_list_window', true, 640, 320);
   }
   
   var qfd_list_select_row;
   
   function fun_qfd_list_update()
   {
      var data_set = $("#qfd_list_grid").jqGrid('getGridParam', 'selarrrow');
      if(data_set.length > 1)
      { 
         $.messager.alert('操作结果','请选择单条再操作！'); 
         return;
      }
	      
      var gr =$("#qfd_list_grid").jqGrid('getGridParam','selrow');
      if(gr != null)
      {
         $("#qfd_list_form")[0].reset(); 
         qfd_list_select_row = jQuery("#qfd_list_grid").jqGrid('getRowData', gr); 
         fun_qfd_list_load_data(qfd_list_select_row);
         
         qfd_list_saveflag = false;
         openUIDialog('qfd_list_window', true, 640, 320);
      }
      else
      {
         $.messager.alert('提示','请先选中一行数据!!');
      }
   }

   function fun_qfd_list_load_data(rowData)
   {
      $('#qfd_list_qfdName').val(qfd_list_select_row.qfdName);
      $('#qfd_list_qfdType').val(qfd_list_select_row.qfdType);
      $('#qfd_list_chargeflag').val(qfd_list_select_row.chargeFlag);
      $('#qfd_list_qfdPrice').val(qfd_list_select_row.qfdPrice);
   }
   
   function  fun_qfd_list_submit()
   { 
      var req_param = new Object();
      req_param.chargeFlag = $('#qfd_list_chargeflag').val();
      req_param.qfdPrice = $('#qfd_list_qfdPrice').val();
      req_param.qfdType = $('#qfd_list_qfdType').val();
      req_param.qfdName = $('#qfd_list_qfdName').val();
      
      if(qfd_list_saveflag)
      {
         req_param.qfdId = '';
         
         //检查是否选择了附件
         var upload_filename = $('#qfd_list_imgfile').val();
         if(upload_filename == null || upload_filename.length == 0)
         {
            alert('请选择上传图片文件！');
            return ;
         }
      }
      else
      {
    	  req_param.qfdId = qfd_list_select_row.qfdId;
      }
      
      $('#qfd_list_req_param').val(JSON.stringify(req_param));
      $('#qfd_list_form')[0].submit();
      
      //openUIDialog('qfd_list_window');
   }
  
   function fun_qfd_list_return_result(error_code)
   {
      if(error_code == 0)
      {
         $.messager.alert('操作提示', '操作成功！');
      }
      else
      {
         $.messager.alert('操作提示', '操作失败，请重试！');
      }
      
      $("#qfd_list_grid").trigger("reloadGrid");
      closeUIDialog('qfd_list_window');
      
      //fun_iepe_load_userscore_data();
   }
   
   function fun_qfd_list_delete()
   {
      var data_set = $("#qfd_list_grid").jqGrid('getGridParam', 'selarrrow');
      if(data_set.length < 1)
      { 
         $.messager.alert('操作结果','请至少选择一条记录再操作!'); 
         return;
      }
      
      var ids = '';
      for ( var i = 0; i < data_set.length; i++)
      {
         if (i > 0)
        	   ids += ',';
         ids += data_set[i];
      }
      
      $.messager.confirm('删除提示', '您确认要删除?', function(r)
    	{   
         if(r)
         {
        	 fun_qfd_list_del(ids);
         }
      });
	   
      /*
      var gr = $("#qfd_list_grid").jqGrid('getGridParam','selrow');
      if(gr != null)
      {
         var rowData = jQuery("#qfd_list_grid").jqGrid('getRowData', gr);
         $.messager.confirm('删除提示','您确认要删除?', function(r)
         {   
            if(r)
            {
               fun_qfd_list_del(rowData.infoId);
            }
         });
      }
      else
      {
         $.messager.alert('提示','请先选中一行数据!!');
      }
      */
   }

   function fun_qfd_list_del(qfdids)
   {
      $.ajax(
      {
          async : false,
         type : "POST",
         url : "qfd/Qfd/delete.do",
         dataType : "json",
         data :
         {
            ids : qfdids
         },
         success : function(json)
         {
            if (json.success)
            {
               $("#qfd_list_grid").trigger("reloadGrid");
               $.messager.alert('操作提示', '操作成功！');
            }
            else
            {
               $.messager.alert('操作提示', '操作失败，请重试！');
            }
         }
      });
   }

   $('#s_qfd_list_query_btn').unbind('click');
   $('#s_qfd_list_query_btn').click(function()
   {
      var s_infoStatus = $('#s_qfd_list_query_infoStatus').val();
      var s_infoTitle = $('#s_qfd_list_query_infoTitle').val();
      var s_beginTimeString = $('#s_qfd_list_query_beginTime').datebox('getValue');
      var s_endTimeString = $('#s_qfd_list_query_endTime').datebox('getValue');
      
      $("#qfd_list_grid").setGridParam(
      {
         url : 'data/Qfdtext/list.do',
         mtype: 'post',
         postData:{'s_infoTitle':s_infoTitle, 's_infoStatus':s_infoStatus, 's_beginTime':s_beginTimeString, 's_endTime':s_endTimeString}
      });
      
      $("#qfd_list_grid").trigger("reloadGrid");
   });

   function fun_qfd_list_preview(objFile)
   {
      var file_name = objFile.value;
      
      //alert(file_name);
      //$('#qfd_list_img_preview').attr("src", "file:///" + file_name);
      //$("#qfd_list_img_preview").attr("src", "g:\1111.png");
      //file_name = $('#qfd_list_img_preview').attr("src");
      //alert(file_name);
   }
   
</script>
